package com.dididoctor.patient.Activity.OneToOneChat.rec;

import android.app.Dialog;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.dididoctor.patient.R;

/**
 * Created by 张强 on 2015/5/3.
 */
public class RecordDialog {

    private Dialog mDialog;
    private TextView tx_msg;
    private ImageView img_icon, img_voice;
    private Context mContext;

    public RecordDialog(Context mContext) {
        this.mContext = mContext;
    }

    public void showRecordDialog() {
        mDialog = new Dialog(mContext, R.style.Theme_Recorder_dialog);
        LayoutInflater inflater = LayoutInflater.from(mContext);
        View view = inflater.inflate(R.layout.dialog_recorder, null);
        tx_msg = (TextView) view.findViewById(R.id.tx_msg);
        img_icon = (ImageView) view.findViewById(R.id.img_recorder_icon);
        img_voice = (ImageView) view.findViewById(R.id.img_voice);
        mDialog.setContentView(view);
        mDialog.show();
    }

    public void wantToCancle() {
        if (mDialog != null && mDialog.isShowing()) {
            img_icon.setImageResource(R.drawable.cancel);
            img_voice.setVisibility(View.GONE);
            tx_msg.setText("松开手指，取消发送");
        }
    }

    public void tooShort() {
        if (mDialog != null && mDialog.isShowing()) {
            img_icon.setImageResource(R.drawable.voice_to_short);
            img_voice.setVisibility(View.GONE);
            tx_msg.setText("录音时间过短");
        }

    }

    public void dismiss() {
        if (mDialog != null && mDialog.isShowing()) {
            mDialog.dismiss();
            mDialog = null;
        }
    }

    public void updateVoiceLevel(int level) {
        if (mDialog != null && mDialog.isShowing()) {
            int resId = mContext.getResources().getIdentifier("v" + level, "drawable", mContext.getPackageName());
            img_voice.setImageResource(resId);
        }
    }

    public void recording() {
        if (mDialog != null && mDialog.isShowing()) {
            img_icon.setImageResource(R.drawable.recorder);
            img_voice.setVisibility(View.VISIBLE);
            tx_msg.setText("手指上滑，取消发送");
        }

    }
}
